1484242483 by Unknown

1484242483 by Unknown

Author:Unknown
Language: eng
Format: epub
Published: 2018-11-30T20:54:33+00:00


Chapter 6 projeCtiles!

}

}

public fireWeapon() {

this.weapon.fire();

this.bulletCount = this.weapon.fireLimit - this.weapon.

shots;

}

public renderPickup(): void {

this.pickup = new Pickup(this.gameInstance, {x: 12,

y: 12});

}

}

Making it to the Big Screen

We are missing one small piece of the puzzle so far—that is, when do we render the pickup on the screen and to what frequency? To see results quickly we shall be sending the coordinates directly on the client side when we instantiate our projectile class. Let’s refresh our memories.

All of the game logic will be in the game.ts file. This means that all of the modules come together with business rules inside of one area. This makes it easy to see what the rules of the games are.

For a much bigger project it is best to exclude the implementation and avoid having everything in one giant file. This also means possibly having the class and the implementation of the game rules on the same directory but in separate files.

We shall be doing this in our final chapter when we refactor the lot. For now let’s keep it simple and implement it directly without any abstractions.

Inside of game.class.ts file we will add the code from Listing 6-5.

64

Chapter 6 projeCtiles!

Listing 6-5. src/client/game/game.class.ts

...

protected manageAssets(game): void {

this.actors = [];

this.actor = new Player(game);

// create a new instance for our projectile which will

render the pickup

// graphic as well. We went for a composition approach

const projectile = new Projectile(game);

// after the instance has been created, just add water :)

projectile.renderPickup();

...

By adding the new projectile and having control when and where it

renders, we can place a graphic illustrating the type of power pickup the player can eventually pickup. We still have a long way to go. We are missing four fundamental features at the moment.

The first missing fundamental is the player having the ability to

pickup the power. This means we should modify the player class with an assign pickup method. The second fundamental is a way to tell the game engine that the player and the pickup have overlapped with each other and to go ahead and assign the pickup to the player who was lucky enough to get ammo.

Third, we need to update our keyboard class to allow the user to fire her cannons while pressing the space bar on the keyboard. The final

fundamental is adding some sort of graphic that the player has picked up the power up. We shall solve this by implementing a HUD.

The HUD will also show the total number of ammo and the remaining

ammo if the player decides to unleash her cannons. We shall solve the first one pretty easily thanks to Phaser. Perform this operation with an overlap method that we shall call during the game loop.

65



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.